﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using SchoolLibrary.Entity;
using SchoolLibrary.Entity.Person;
using SchoolLibrary.DataBase.DAO;

namespace SchoolLibrary.DataBase.Builder
{
    class ClassBuilder : AbstractEntityBuilder
    {
        public override Identity Build(DataRow row)
        {
            Class schoolClass = new Class();
            BuildEntity(schoolClass, row);
            return schoolClass;
        }

        protected override void BuildEntity(Identity entity, DataRow row)
        {
            base.BuildEntity(entity, row);           
            Class schoolClass = (Class)entity;

            byte number = Byte.Parse(row[Class.NUMBER_COLUMN_NAME].ToString());
            schoolClass.Number = number;

            string letter = row[Class.LETTER_COLUMN_NAME].ToString();
            schoolClass.Letter = letter;

            long classLeaderId = Int32.Parse(row[Class.CLASS_LEADER_ID_COLUMN_NAME].ToString());
            ClassLeader classLeader = ClassLeaderDAO.getInstance().findById(classLeaderId);
            schoolClass.ClassLeader = classLeader;
        }
    }
}
